// vite.config.ts
import { defineConfig ,loadEnv} from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
//svg精灵图标
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import WindiCSS from 'vite-plugin-windicss'


export default defineConfig(({ mode }) => {
  // 加载环境变量
  const env = loadEnv(mode, process.cwd(), '');
   return {
    plugins: [
    vue(),
        WindiCSS(),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: 'less', // 如果使用less主题定制
          // importStyle: 'css' // 如果只使用css
        })
      ]
    }),
    
    createSvgIconsPlugin({
      // 指定图标文件夹，绝对路径（NODE代码）
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')]
   })
  ],
  
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          // 可以在这里自定义主题变量
        }
      }
    }
  },
  
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
   server: {
      port: 3000,
      // 开发环境代理配置
      proxy: {
        '/api': {
          target: env.VITE_API_BASE_URL || 'http://localhost:8080',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    build: {
      // 生产环境构建配置
      outDir: 'dist',
      assetsDir: 'static',
      sourcemap: mode === 'development'
    }
   }

});
